/**
 * 
 */
package org.rollinitiative.d20web.charactersheet.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

/**
 * This view displays the characters health attributes, which includes hit points and any effects
 * currently afflicting them.
 * 
 * @author bebopjmm
 * 
 */
public class HealthView extends Composite
{
    private final TextBox currHPText_ = new TextBox();
    private final TextBox maxHPText_ = new TextBox();
    private final TextBox currRPText_ = new TextBox();
    
    private final FlexTable effectsTable_ = new FlexTable();


    public HealthView()
    {
        Grid hpGrid = new Grid(3, 2);
        hpGrid.setWidget(0, 0, new Label("Hit Points"));
        hpGrid.setWidget(0, 1, currHPText_);
        currHPText_.setSize("4em", "2em");
        hpGrid.setWidget(1, 0, new Label("Reserve Points"));
        hpGrid.setWidget(1, 1, currRPText_);
        currRPText_.setSize("4em", "2em");
        hpGrid.setWidget(2, 0, new Label("of Max"));
        hpGrid.setWidget(2, 1, maxHPText_);
        maxHPText_.setSize("4em", "2em");
        
        // Setup the table
        effectsTable_.setCellSpacing(1);
        effectsTable_.setCellPadding(1);
        effectsTable_.setWidth("50%");
        // Create the header row.
        effectsTable_.setText(0, 0, "Effects");
        
        HorizontalPanel panel = new HorizontalPanel();
        panel.setSpacing(2);
        panel.add(hpGrid);
        panel.add(effectsTable_);

        // Hook up events.

        initWidget(panel);
        init();
    }
    
    public void setCharacter(HealthData health)
    {
        currHPText_.setText("" + health.getCurrentHP());
        maxHPText_.setText("" + health.getMaxHP());
        currRPText_.setText("" + health.getCurrentRP());
    }
    
    
    void init()
    {
        currHPText_.setText("0");
        maxHPText_.setText("0");
        currRPText_.setText("0");
    }
}
